package org.springblade.modules.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.*;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.service.IElevatorStopLogService;
import org.springblade.modules.admin.service.MaintainBusinessLogService;
import org.springblade.modules.admin.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.Date;


/**
 * 业务日志查询接口：所属梯组日志、责任人分配日志
 * @author: Sharry
 * @createTime: 2023/2/9 17:13
 * @version: Version-1.0
 */

@Api(tags = "业务日志查询接口", value = "/business/logs")
@RestController
@RequestMapping("/business/logs")
public class BusinessLogController {

	@Autowired
	private MaintainBusinessLogService maintainBusinessLogService;

	@Autowired
	private IElevatorStopLogService elevatorStopLogService;


	/**
	 * 根据业务类型及关键字Id查询分业日志
	 * 可通过时间筛选
	 */
	@GetMapping("/logPage")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "根据param及type日志分页")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "paramKey", value = "日志paramKey", example = "1"),
		@ApiImplicitParam(name = "type", value = "日志类型", example = "2"),
		@ApiImplicitParam(name = "beginTime", value = "开始时间", example = "2023-02-09 16:50:46"),
		@ApiImplicitParam(name = "endTime", value = "结束时间", example = "2023-02-10 17:50:46")
	})
	public R<IPage<MaintainBusinessLogVO>> businessLogPage(Query query, Long paramKey, Integer type, String beginTime, String endTime){

		IPage<MaintainBusinessLogVO> pages
			= maintainBusinessLogService.selectLogPages(Condition.getPage(query), paramKey, type, beginTime, endTime);
		return R.data(pages);
	}

	/**
	 * 根据电梯 Id 查询单梯运行状态日志
	 * 可通过时间筛选
	 */
    @GetMapping("/elevatorStopLogPage")
	@ApiOperation("根据id 查询单台电梯停梯日志")
	@ApiOperationSupport(order = 2)
	@ApiImplicitParams({
    	@ApiImplicitParam(name = "elevatorId", value = "电梯id", example = "1521835004028059650"),
		@ApiImplicitParam(name = "beginTime", value = "开始时间", example = "2023-02-09 16:50:46"),
		@ApiImplicitParam(name = "endTime", value = "结束时间", example = "2023-02-10 17:50:46")
	})
	public R<IPage<ElevatorStopLogVO>> elevatorStopLogPage(Query query, Long elevatorId, String beginTime, String endTime,String userIds,Integer source,Integer module){
		IPage<ElevatorStopLogVO> pages =
			elevatorStopLogService.selectStopLogPageById(Condition.getPage(query), elevatorId, beginTime, endTime,Func.toLongList(userIds),source,module);
		return R.data(pages);
	}

	/**
	 * 根据电梯 Id 查询单梯部分关系信息
	 */
	@GetMapping("/getElevatorDetail")
	@ApiOperation("根据id 查询单台电梯部分信息")
	@ApiOperationSupport(order = 3)
	@ApiImplicitParam(name = "elevatorId", value = "电梯id", example = "1000000000000000014")
	public R<ElevatorRelationDetailVO> getSingleDetail(Long elevatorId){
		ElevatorRelationDetailVO detailVO = maintainBusinessLogService.getRelationDetail(elevatorId);
		return R.data(detailVO);
	}

	/**
	 * 根据电梯 Id 查询单梯 维保签字日志
	 */
	@GetMapping("/getElevatorSignLog")
	@ApiOperation("根据电梯 id 查询维保签字日志")
	@ApiOperationSupport(order = 4)
	public R<IPage<ElevatorSignLogVO>> getSingleSignLog(Long elevatorId, String beginTime, String endTime, Query query) {
		String tenantId = AuthUtil.getTenantId();
		IPage<ElevatorSignLogVO> page = maintainBusinessLogService.getSingleSignLog(elevatorId, beginTime, endTime, Condition.getPage(query),tenantId);
		return R.data(page);
	}

	/**
	 * 根据电梯 Id 查询单梯 维修记录
	 */
	@GetMapping("/getElevatorRepairLog")
	@ApiOperation("根据电梯 id 查询维修记录")
	@ApiOperationSupport(order = 5)
    public R<IPage<ElevatorRepairLogVO>> getSingleRepairLog(Long elevatorId, Date beginTime, Date endTime, Query query) {
		IPage<ElevatorRepairLogVO> page = maintainBusinessLogService.getSingleRepairLog(elevatorId, beginTime, endTime, Condition.getPage(query));
        return R.data(page);
    }

	/**
	 * 根据电梯 Id 查询单梯 救援记录
	 */
	@GetMapping("/getElevatorRescueLog")
	@ApiOperation("根据电梯 id 查询救援记录")
	@ApiOperationSupport(order = 6)
    public R<IPage<ElevatorRescueLogVO>> getSingleRescueLog(Long elevatorId, Date beginTime, Date endTime, Query query) {
        IPage<ElevatorRescueLogVO> page = maintainBusinessLogService.getSingleRescueLog(elevatorId, beginTime, endTime, Condition.getPage(query));
        return R.data(page);
    }

}
